package com.zxx.retrofit;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.zxx.retrofit.bean.LoginUser;
import com.zxx.retrofit.net.RetrofitHelper;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

    private Button retrofit_test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        retrofit_test = (Button) findViewById(R.id.retrofit_test);
    }

    public void retrofit_test(View view) {
//        Call<LoginUser> call = RetrofitHelper.getBombLoinApi().queryUser("ad4b3929f3");
//        call.enqueue(new Callback<LoginUser>() {
//            @Override
//            public void onResponse(Call<LoginUser> call, Response<LoginUser> response) {
//                Log.d("zxx", "onResponse:" + response.body().toString());
//            }
//
//            @Override
//            public void onFailure(Call<LoginUser> call, Throwable t) {
//                Log.e("zxx", "onFailure:" + t.getMessage());
//            }
//        });
        Call<String> call = RetrofitHelper.getDoubanApi().getSearchBook("小王子", "", 0, 3);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                Log.d("zxx", "onResponse response:" + response.body() + ",call:" + call.toString());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Log.e("zxx", "onFailure:" + t.getMessage());
            }
        });
    }
}
